package entities;

import interfaze.SpaceInvadersGamingPanel;

import java.awt.Image;
import java.util.ArrayList;

import javax.swing.ImageIcon;

import logic.Utilities;

@SuppressWarnings("serial")
public class Bouncer extends Enemy {

	private ImageIcon icon;
	
	/*public Bouncer(int x, int y, float xScale, float yScale) {
		super(x, y);
		Image image = Utilities.loadImage("res/Bouncer.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/Bouncer.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds(this.x, this.y, this.width, this.height);
	}*/

	/**
	 * 
	 * @param x
	 * @param y coordinates
	 * @param dx
	 * @param dy speed
	 * @param xScale
	 * @param yScale scale
	 * @param fila the row to which the bouncer belongs, although there's only the bouncer in the bouncer row
	 * @param p the panel to which the bouncer belongs
	 */
	public Bouncer(int x, int y, int dx, int dy, float xScale, float yScale,ArrayList<Enemy>fila, SpaceInvadersGamingPanel p) {
		super(x, y, dx, dy,fila,p);
		Image image = Utilities.loadImage("res/Bouncer.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/Bouncer.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
		lastUpdate=System.currentTimeMillis();
	}
	
	public static int getWidth(float xScale) {
		return Math.round(42 * xScale);
	}
	
	public static int getHeight(float yScale) {
		return Math.round(75 * yScale);
	}
	/**
	 * this method creates two enemy shots which are supposed to move in a diagonal fashion in opposed directions, and should "bounce off" the sides of the screen, thus the name "bouncer"
	 * @param velY the vertical speed at which these shots should move
	 * @param lDispB the ArrayList containing all the Enemy Shots on screen
	 */
	public void dispara( int velY, ArrayList<EnemyShot>lDispB) {
		EnemyShot temp=null;
		int velX=velY;
		System.out.println(velX+", "+-velX);
			temp=new EnemyShot((int) (this.x+(this.getBounds().getWidth()/2)), (int) (this.y+(this.getBounds().getHeight())), Math.abs(velX), velY, p);
			lDispB.add(temp);
			p.add(temp,0);
			temp=new EnemyShot((int) (this.x+(this.getBounds().getWidth()/2)), (int) (this.y+(this.getBounds().getHeight())), -Math.abs(velX), velY, p);
			lDispB.add(temp);
			p.add(temp, 0);
	}
}
